
module.exports = class extends think.Model {
  async add({label, orderNo, domain, expireTime, user}) {
    const json = [ {
      type: 1,
      label: '发布成功',
      title: `订单：【${orderNo}】发布成功`,
      content: `您的订单：【${orderNo}】已审核通过，该订单域名"${domain}"已发布`
    }, {
      type: 1,
      label: '发布失败',
      title: `订单：【${orderNo}】发布失败`,
      content: `您的订单：【${orderNo}】没有审核通过，该订单域名"${domain}"已驳回`
    }, {
      type: 2,
      label: '买家支付',
      title: `订单：【${orderNo}]买家已支付`,
      content: `您的订单：【${orderNo}】买家已支付，回购日期为：${expireTime}`
    }, {
      type: 4,
      label: '延期申请通过',
      title: `订单：【${orderNo}】延期申请通过`,
      content: `您的域名"${domain}"卖家已同意延期您的申请，请您付款`
    }, {
      type: 4,
      label: '延期申请成功',
      title: `订单：【${orderNo}】延期申请成功`,
      content: `您的订单：【${orderNo}】已延期成功，回购日期已变更为：${expireTime}`
    }, {
      type: 4,
      label: '延期申请失败',
      title: `订单：【${orderNo}】延期申请失败`,
      content: `您的域名"${domain}"买家已拒绝延期您的申请`
    }, {
      type: 3,
      label: '订单回购成功',
      title: `订单：【${orderNo}】回购完成`,
      content: `您的域名"${domain}"已完成回购`
    }, {
      type: 3,
      label: '订单未回购',
      title: `订单：【${orderNo}】已完成`,
      content: `域名"${domain}"未回购，将过户至您的账户`
    }, {
      type: 3,
      label: '申诉驳回',
      title: `订单：【${orderNo}】申诉驳回`,
      content: `您的域名"${domain}"申诉失败系统驳回，详细信息请联系客服`
    }, {
      type: 3,
      label: '对方提交证据',
      title: `订单：【${orderNo}】对方已经提交申诉证据`,
      content: `您的域名"${domain}"对方已经提交申诉证据请及时查看`
    }, {
      type: 3,
      label: '申诉胜诉',
      title: `订单：【${orderNo}】您已胜诉`,
      content: `您的域名"${domain}"申诉胜利，系统判定您已胜诉，详细信息请联系客服`
    }, {
      type: 3,
      label: '申诉败诉',
      title: `订单：【${orderNo}】您已败诉`,
      content: `您的域名"${domain}"申诉失败，系统判定您已败诉，详细信息请联系客服`
    }, {
      type: 2,
      label: '支付成功',
      title: `订单：【${orderNo}】已完成支付`,
      content: `您的订单：【${orderNo}】已完成支付进入回购期，回购日期为：${expireTime}`
    }, {
      type: 4,
      label: '延期申请',
      title: `订单：【${orderNo}】延期申请`,
      content: `您的订单：【${orderNo}】卖家申请延期及时处理`
    }];
    for (const item of json) {
      if (item.label === label) {
        const u = await this.model('user_list').where({id: user}).find();
        think.service('tuisong', 'admin').sendSingle(u.cid, label, item.title);
        this.model('notice').add({
          create_time: ['exp', 'CURRENT_TIMESTAMP()'],
          title: item.title,
          content: item.content,
          type: item.label,
          status: item.type,
          user_id: user
        });
        break;
      }
    }
  }
};
